package com.smt.modules.app.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.smt.common.enums.Code;
import com.smt.common.utils.EnumToKeyUtil;
import com.smt.common.utils.PageUtils;
import com.smt.common.utils.R;
import com.smt.common.utils.StringToListUtil;
import com.smt.modules.app.annotation.Login;
import com.smt.modules.app.annotation.LoginUser;
import com.smt.modules.bus.entity.AddressBookEntity;
import com.smt.modules.bus.entity.InviteEntity;
import com.smt.modules.bus.entity.MemberUserEntity;
import com.smt.modules.bus.service.AddressBookService;
import com.smt.modules.bus.service.TeamManagementService;
import com.smt.modules.bus.vo.request.ProjectSiReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;

/**
 * 团队管理
 *
 * @author zhangyi
 * @date 2018/10/10 15:10
 */
@RestController
@RequestMapping("/app/team")
@Api(tags = {"AppTeamManagementController"},description = "团队管理(客户端接口)")
public class AppTeamManagementController {

    @Resource
    private TeamManagementService teamManagementService;



    /**
     *  获取该项目下的成员列表
     *
     * @param projectSiReq
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取该项目下的成员列表(选填阶段id，可以获取当前项目下的阶段所有成员)",httpMethod = "GET")
    public R list(ProjectSiReq projectSiReq){
        R list = teamManagementService.list(projectSiReq);
        return list;
    }

    /**
     *  上传头像
     *
     * @param headImg
     * @return
     */
    @Login
    @PostMapping("/uploadHeadImg")
    @ApiOperation(value = "上传头像",httpMethod = "POST")
    public R uploadHeadImg(String headImg, @LoginUser MemberUserEntity memberUserEntity){
        return teamManagementService.uploadHeadImg(headImg,memberUserEntity);
    }

    /**
     *  从该项目中移除该成员
     *
     * @param projectId
     * @param userId
     * @return
     */
    @Login
    @DeleteMapping("/remove/{projectId}/{userId}")
    @ApiOperation(value = "从该项目中移除该成员",httpMethod = "DELETE")
    public R remove(@PathVariable("projectId")@NotEmpty(message = "项目id不能少") Long projectId,
                    @PathVariable("userId") @NotEmpty(message = "用户id不能少") Long userId,
                    @LoginUser MemberUserEntity entity){
        R list = teamManagementService.remove(projectId,userId,entity);
        return list;
    }

    /**
     *  加入该公司 TODO
     *
     *  内部登录注册后确定加入该公司
     *
     * @param creatorId 创建者id
     * @return
     */
    @Login
    @PostMapping("/join/{creatorId}")
    @ApiOperation(value = "加入该公司",httpMethod = "POST")
    public R join(@PathVariable("creatorId") Long creatorId,
                  @LoginUser MemberUserEntity memberUserEntity){

        return teamManagementService.join(creatorId,memberUserEntity);
    }

    /**
     *  获取团队下的成员集合
     *
     * @param teamId 团队id
     * @return
     */
    @Login
    @GetMapping("/teamMembers/{teamId}")
    @ApiOperation(value = "获取团队下的成员集合",httpMethod = "GET")
    public R teamMembers(@PathVariable("teamId") Long teamId,
                  @LoginUser MemberUserEntity memberUserEntity){

        return teamManagementService.teamMembers(teamId,memberUserEntity);
    }

}
